#include <iostream>

using namespace std;
// const int maxLen=200000;


int main()
{
    int n;
    int *sum;
	scanf("%d",&n);
    // a=new int[n];
    // b=new int[n];
    sum=new int[n+1];
    int lastx,lasty;
    int nowx;
	
    cin >> lastx >> lasty;
    int i;

    sum[1]=0;
    for(i=1;i<n;i++)
    {
        scanf("%d",&nowx);
        int num=nowx-lasty-lastx;
        scanf("%d",&lasty);
        lastx=nowx;

        if(num<0)
        {
            num=0;
        }
        sum[i+1]=sum[i]+num;
    }

    int m,x,y;

	

    scanf("%d",&m);
	const int len=m;
	int *result=new int[m];
    for(i=0;i<m;i++)
    {
        scanf("%d %d",&x,&y);
        result[i]=sum[y]-sum[x];
    }
	for(i=0;i<m;i++)
    {
		printf("%d\n",result[i]);
        // cout << result[i] <<endl;
	}

    delete [] result; 
    delete [] sum; 

    // delete sum;

    return 0;
}